import { apiClient } from './axios';

// 区域管理相关接口
export const areasApi = {
  // 获取区域列表
  getAreas: (params?: {
    page?: number;
    per_page?: number;
    search?: string;
    include_members?: boolean;
  }) => {
    return apiClient.get('/areas', { params });
  },

  // 获取单个区域详情
  getArea: (areaId: number, params?: { include_members?: boolean }) => {
    return apiClient.get(`/areas/${areaId}`, { params });
  },

  // 获取区域选项列表（用于下拉选择）
  getAreaOptions: () => {
    return apiClient.get('/areas/options');
  },

  // 创建区域
  createArea: (areaData: {
    name: string;
    leader_id?: number;
    description?: string;
    is_active?: boolean;
  }) => {
    return apiClient.post('/areas', areaData);
  },

  // 更新区域
  updateArea: (areaId: number, areaData: {
    name?: string;
    leader_id?: number;
    description?: string;
    is_active?: boolean;
  }) => {
    return apiClient.put(`/areas/${areaId}`, areaData);
  },

  // 删除区域
  deleteArea: (areaId: number) => {
    return apiClient.delete(`/areas/${areaId}`);
  },

  // 获取区域成员列表
  getAreaMembers: (areaId: number) => {
    return apiClient.get(`/areas/${areaId}/members`);
  },

  // 添加区域成员
  addAreaMember: (areaId: number, userId: number) => {
    return apiClient.post(`/areas/${areaId}/members`, { user_id: userId });
  },

  // 移除区域成员
  removeAreaMember: (areaId: number, userId: number) => {
    return apiClient.delete(`/areas/${areaId}/members/${userId}`);
  },

  // 批量更新区域成员
  updateAreaMembers: (areaId: number, userIds: number[]) => {
    return apiClient.put(`/areas/${areaId}/members`, { user_ids: userIds });
  }
};